package cn.shyouchi.wuguanjia.android.ui.event.meet;

import android.content.Context;
import android.support.annotation.NonNull;

import java.util.List;

import cn.shyouchi.wuguanjia.android.api.event.EventApi;
import cn.shyouchi.wuguanjia.android.model.BaseRequestResult;
import cn.shyouchi.wuguanjia.android.subscribers.ProgressSubscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Func1;
import rx.schedulers.Schedulers;

/**
 * Created by Eenie on 2016/11/18 at 9:24
 * Email: 472279981@qq.com
 * Des:
 */

public class EventMeetPresenter implements EventMeetContract.Presenter {

    Context mContext;
    EventMeetContract.View mView;
    EventApi mEventApi;

    public EventMeetPresenter(Context context, EventMeetContract.View view) {
        this.mContext = context;
        this.mView = view;
        mEventApi = new EventApi(mContext);
    }


    @Override
    public void getMeetList(String projectId) {
        mEventApi.getMeetList(projectId)
                .subscribeOn(Schedulers.io())
                .map(new Func1<EventMeetEntity, List<EventMeetEntity.ResultMessageBean>>() {
                    @Override
                    public List<EventMeetEntity.ResultMessageBean> call(EventMeetEntity entity) {
                        return entity.getResultMessage();
                    }

                })
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ProgressSubscriber<List<EventMeetEntity.ResultMessageBean>>(mContext) {
                    @Override
                    public void onNext(List<EventMeetEntity.ResultMessageBean> resultMessageBeen) {
                        mView.onDataRefresh(resultMessageBeen);
                    }
                });
    }

    @Override
    public void delMeet(final String projectId, String id) {
        mEventApi.delMeet(id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ProgressSubscriber<BaseRequestResult>(mContext) {
                    @Override
                    public void onNext(BaseRequestResult result) {
                        getMeetList(projectId);
                    }
                });

    }

    @Override
    public void attachView(@NonNull EventMeetContract.View view) {

    }

    @Override
    public void detachView() {

    }
}
